
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@page import="src.Game"%>
<%@page import="java.io.*"%>
<jsp:useBean id="game" class="src.Game" scope="application"/>

<%
    if (session.getAttribute("playerID") != null) {
        double effort = -1.0;
        String playerid = session.getAttribute("playerID").toString();
        int playerID = Integer.parseInt(playerid);
        boolean flag = true;


        if ("Increase Effort".equals(request.getParameter("command"))) {

            try {

                effort = Game.compute(playerID, 1); // +1 for increase
                out.println("Player : " + playerID + " effort is " + effort);
                response.sendRedirect("image.jsp");
                flag = false;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


        if ("Decrease Effort".equals(request.getParameter("command"))) {
            try {

                effort = Game.compute(playerID, -1); // -1 for decrease
                out.println("Player : " + playerID + " effort is " + effort);
                response.sendRedirect("image.jsp");
                flag = false;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        if (flag) {
            try {
                Game.compute(playerID, 0); // 0 for neither decrease nor increase
                response.sendRedirect("image.jsp");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

%>











